<?php

/**
 * This is the model class for table "student".
 *
 * The followings are the available columns in table 'student':
 * @property integer $id
 * @property string $romaji
 * @property integer $male
 * @property string $url_avatar
 * @property string $birth_date
 * @property string $id_NO
 * @property integer $mem_id
 * @property string $student_NO
 * @property string $address
 * @property string $phone
 * @property string $mobile
 * @property string $father_name
 * @property string $father_phone
 * @property string $class_name
 * @property integer $final_year
 * @property integer $final_month
 * @property string $final_address
 * @property string $final_schoolAddress
 * @property string $studying_schoolName
 * @property string $studying_faculty
 * @property string $studying_dept
 * @property string $studying_grade
 * @property integer $language_type
 * @property string $ad_date
 * @property string $conf_date
 * @property string $phonetic
 * @property string $job_objective
 * @property string $admiss_purpose
 * @property string $note
 * @property string $sign_date
 * @property string $sign
 */
class Student extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'student';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('romaji, male, url_avatar, birth_date, id_NO, student_NO, address, phone, mobile, father_name, father_phone, class_name, language_type, phonetic', 'required'),
			array('id, male, mem_id, final_year, final_month, language_type', 'numerical', 'integerOnly'=>true),
			array('romaji, url_avatar, id_NO, student_NO, address, father_name, class_name, studying_schoolName, studying_faculty, studying_dept, studying_grade, phonetic', 'length', 'max'=>255),
			array('phone, mobile, father_phone', 'length', 'max'=>20),
			array('final_address, final_schoolAddress, ad_date, conf_date, job_objective, admiss_purpose', 'safe'),
                        array('father_phone','match','pattern'=>'/^-?[\d,.]*$/'),
                        array('mobile','match','pattern'=>'/^-?[\d,.]*$/'),
                        array('phone','match','pattern'=>'/^-?[\d,.]*$/'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, romaji, male, url_avatar, birth_date, id_NO, mem_id, student_NO, address, phone, mobile, father_name, father_phone, class_name, final_year, final_month, final_address, final_schoolAddress, studying_schoolName, studying_faculty, studying_dept, studying_grade, language_type, ad_date, conf_date, phonetic', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'romaji' => Yii::t('strings','Romaji character'),
			'male' => 'Male',
			'url_avatar' => 'Url Avatar',
			'birth_date' => Yii::t('strings','Birthday'),
			'id_NO' => Yii::t('strings','ID No'),
			'mem_id' => 'Mem',
			'student_NO' => Yii::t('strings','Student No.'),
			'address' => Yii::t('strings','Present address'),
			'phone' => Yii::t('strings','Phone number'),
			'mobile' => Yii::t('strings','Mobile number'),
			'father_name' => Yii::t('strings','Your father name'),
			'father_phone' => Yii::t('strings','Your father phone number'),
			'class_name' => Yii::t('strings','Class name'),
			'final_year' => Yii::t('strings','Year'),
			'final_month' => 'Final Month',
			'final_address' => 'School Name',
			'final_schoolAddress' => Yii::t('strings','School Address'),
			'studying_schoolName' => Yii::t('strings','School Name'),
			'studying_faculty' => Yii::t('strings','Faculty'),
			'studying_dept' => Yii::t('strings','Department'),
			'studying_grade' => 'Grade',
			'language_type' => 'Language Type',
			'ad_date' => 'Ad Date',
			'conf_date' => 'Conf Date',
			'phonetic' => Yii::t('strings','Phonetic'),
                        'job_objective'=>Yii::t('strings','Job objective'),
                        'admiss_purpose'=>Yii::t('strings','Admission purpose'),
                        'note'=>Yii::t('strings', 'Note'),
                        'sign_date'=>Yii::t('strings','Sign Date'),
                        'sign'=>Yii::t('strings','Sign'),
		);
	}
        public function getFinalYear(){
            return array(
                '1980'=>'1980',
                '1981'=>'1981',
                '1982'=>'1982',
                '1983'=>'1983',
                '1984'=>'1984',
                '1985'=>'1985',
                '1986'=>'1986',
                '1987'=>'1987',
                '1988'=>'1988',
                '1989'=>'1989',
                '1990'=>'1990',
                '1991'=>'1991',
                '1992'=>'1992',
                '1993'=>'1993',
                '1994'=>'1994',
                '1995'=>'1995',
                '1996'=>'1996',
                '1997'=>'1997',
                '1998'=>'1998',
                '1999'=>'1999',
                '2000'=>'2000'
            );
        }
        public function getFinalMonth(){
            return array(
                '1'=>'1月',
                '2'=>'2月',
                '3'=>'3月',
                '4'=>'4月',
                '5'=>'5月',
                '6'=>'6月',
                '7'=>'7月',
                '8'=>'8月',
                '9'=>'9月',
                '10'=>'10月',
                '11'=>'11月',
                '11'=>'12月'
            );
        }
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('romaji',$this->romaji,true);
		$criteria->compare('male',$this->male);
		$criteria->compare('url_avatar',$this->url_avatar,true);
		$criteria->compare('birth_date',$this->birth_date,true);
		$criteria->compare('id_NO',$this->id_NO,true);
		$criteria->compare('mem_id',$this->mem_id);
		$criteria->compare('student_NO',$this->student_NO,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('father_name',$this->father_name,true);
		$criteria->compare('father_phone',$this->father_phone,true);
		$criteria->compare('class_name',$this->class_name,true);
		$criteria->compare('final_year',$this->final_year);
		$criteria->compare('final_month',$this->final_month);
		$criteria->compare('final_address',$this->final_address,true);
		$criteria->compare('final_schoolAddress',$this->final_schoolAddress,true);
		$criteria->compare('studying_schoolName',$this->studying_schoolName,true);
		$criteria->compare('studying_faculty',$this->studying_faculty,true);
		$criteria->compare('studying_dept',$this->studying_dept,true);
		$criteria->compare('studying_grade',$this->studying_grade,true);
		$criteria->compare('language_type',$this->language_type);
		$criteria->compare('ad_date',$this->ad_date,true);
		$criteria->compare('conf_date',$this->conf_date,true);
		$criteria->compare('phonetic',$this->phonetic,true);
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Student the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
